// ****************************************************************
// Copyright 2012, Stephan Burguchev
// e-mail: me@sburg.net
// ****************************************************************
// *
using System;
using System.IO;

namespace Updater.tmp
{
    /// <summary>
    ///     An update command adding or replacing a file in the application directory.
    /// </summary>
    public class AddFileCommand : IUpdateCommand
    {
        /// <summary>
        ///     Initializes a new instance of the <see cref="AddFileCommand" /> class.
        /// </summary>
        /// <param name="filename">
        ///     The filename (just a file name, not a full path) to be added.
        /// </param>
        public AddFileCommand(string filename)
        {
            if (filename == null)
            {
                throw new ArgumentNullException("filename");
            }

            this.Filename = filename;
        }

        /// <summary>
        ///     Gets a name of the file to be added. Just a file name, not a full path.
        /// </summary>
        public string Filename { get; private set; }

        /// <summary>
        ///     Perform the actions updating the resouces locked by the application and therefore supposing
        ///     to execute when the application is not running.
        /// </summary>
        /// <param name="update">
        ///     The update.
        /// </param>
        public void ExecuteLauncherStartupActions(Update update)
        {
            File.Copy(
                Path.Combine(update.UnpackedUpdateDirectory, this.Filename),
                Path.Combine(update.ApplicationDirectory, this.Filename),
                true);
        }

        /// <summary>
        ///     Perform the actions capable to execute when the installed version of the application is still running.
        /// </summary>
        /// <param name="update">
        ///     The update.
        /// </param>
        public void Prepare(Update update)
        {
        }
    }
}
